package cn.edu.gdpt.mobile0123456789hwh0320;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {
//1、定义全局变量
    private ImageView ivMainLight;
    private Button btnMainLightOn;
    private Button btnMainLightOff;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();//3、调用控件初始化方法
//        4、给开灯按钮设置点击事件监听器
        btnMainLightOn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //在处理单元中设置开灯效果图片
                ivMainLight.setImageResource(R.drawable.light_on);
            }
        });
//        5、给关灯按钮设置点击事件监听器
        btnMainLightOff.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                ivMainLight.setImageResource(R.drawable.light_off);
            }
        });
    }
//2、定义InitView（）控件初始化方法，调用findViewById方法获取控件
    private void initView() {
        ivMainLight = (ImageView) findViewById(R.id.ivMainLight);
        btnMainLightOn = (Button) findViewById(R.id.btnMainLightOn);
        btnMainLightOff = (Button) findViewById(R.id.btnMainLightOff);
    }
}